package com.nsoft.html5npub.utils;

import com.nsoft.html5npub.objects.BookRange;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

@SuppressWarnings("deprecation")
public class BookNewListAdapter extends BaseAdapter {
    private Context mContext;
    /**
    private Bitmap[] bmps;
    */
    private BookRange bookRange;
    private int newBookListHeight;
    private int bookDistance;
    
    public BookNewListAdapter(Context c,/**Bitmap[] _bmps,*/
    		BookRange range,int _bookListHeight) {
    	this.mContext=c;
    	this.bookRange=range;
    	/**
    	this.bmps=_bmps;
    	*/
    	this.newBookListHeight=_bookListHeight;
    	this.bookDistance=utils.
    		getDeviceMetrics(c).widthPixels/2;
    }
    
    public int getCount() {
    	/**
        return this.bmps.length;
    	*/
    	return (this.bookRange.endIndex-
    			this.bookRange.startIndex)+1;
    }

    public Object getItem(int position){
        return position;
    }

    public long getItemId(int position){
        return position;
    }

    public View getView(int position,View convertView, 
    							ViewGroup parent){
        ImageView i=new ImageView(mContext);
        Bitmap bmp=engine.getThumbFromBook(
        					position);
        i.setImageBitmap(bmp);
        i.setLayoutParams(new CoverFlow.
        	LayoutParams(this.bookDistance,
        			(this.newBookListHeight-40)));
        i.setScaleType(ScaleType.FIT_CENTER);
        BitmapDrawable drawable=(BitmapDrawable)i.
        					getDrawable();
        drawable.setAntiAlias(true);
        return i;
    }
	
}
